package com.laiyizhan.cms.first.controller;

import com.laiyizhan.cms.first.request.SeventhRequest;
import com.laiyizhan.cms.first.service.ISeventhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * Created by SoulWolf on 2017/7/21.
 */
@Controller
@RequestMapping("/admin")
public class SeventhController {

    @Autowired
    ISeventhService seventhService;


    /*目录页面*/
    @RequestMapping(value = "/seventh/index/show")
    public String Fifth_index(SeventhRequest request,HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        httpSession.setAttribute("number", 1);
        modelMap.put("state",seventhService.Seventh_index(request));
        return "/seventh/index";
    }



    @RequestMapping(value = "/seventh/a/show")
    public String seventh_a(SeventhRequest request) {
        return "/seventh/main";
    }
    @RequestMapping(value = "/seventh/a")
    public String Seventh_a_record(SeventhRequest request, HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        String result = seventhService.Seventh_a(request);
        modelMap.put("state",seventhService.Seventh_index(request));
        if(result=="no"){
            modelMap.put("error","当职称人数不为0的时候，该职称的在职工年人均工资也不能为0");
            modelMap.put("link","/admin/seventh/a/show");
            return "/error/error";
        }
        return "/seventh/index";
    }

    @RequestMapping(value = "/seventh/b/show")
    public String seventh_b(SeventhRequest request) {
        return "/seventh/b";
    }
    @RequestMapping(value = "/seventh/b")
    public String Seventh_b_record(SeventhRequest request,HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        seventhService.Seventh_b(request);
        modelMap.put("state",seventhService.Seventh_index(request));
        return "/seventh/index";
    }

    @RequestMapping(value = "/seventh/c/show")
    public String seventh_c(SeventhRequest request) {
        return "/seventh/c";
    }
    @RequestMapping(value = "/seventh/c")
    public String Seventh_c_record(SeventhRequest request,HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        seventhService.Seventh_c(request);
        modelMap.put("state",seventhService.Seventh_index(request));
        int order = (int)httpSession.getAttribute("number");
        if (order < 10) {
           httpSession.setAttribute("number",order+1);
        } else {
            return "seventh/index";
        }
        return "/seventh/c";
    }


    @RequestMapping(value = "/seventh/d/show")
    public String Seventh_d() {
        return "/seventh/d";
    }
    @RequestMapping(value = "/seventh/d")
    public String Seventh_d_record(SeventhRequest request,HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        seventhService.Seventh_d(request);
        modelMap.put("state",seventhService.Seventh_index(request));
        return "/seventh/index";
    }

    @RequestMapping(value = "/seventh/e/show")
    public String Seventh_e() {
        return "/seventh/e";
    }
    @RequestMapping(value = "/seventh/e")
    public String Seventh_e_record(SeventhRequest request,HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        seventhService.Seventh_e(request);
        modelMap.put("state",seventhService.Seventh_index(request));
        return "/seventh/index";
    }



}
